package cn.iocoder.yudao.module.asasc.dal.mysql.selesreport;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.asasc.controller.admin.salesreport.vo.SalesReportPageReqVO;
import cn.iocoder.yudao.module.asasc.dal.dataobject.salesreport.SalesReportDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * ASA管理系统 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface SalesReportMapper extends BaseMapperX<SalesReportDO> {

    default PageResult<SalesReportDO> selectPage(SalesReportPageReqVO reqVO) {
        LambdaQueryWrapperX<SalesReportDO> queryWrapper = new LambdaQueryWrapperX<SalesReportDO>()
                .eqIfPresent(SalesReportDO::getProvider, reqVO.getProvider())
                .eqIfPresent(SalesReportDO::getOrgId, reqVO.getOrgId())
                .eqIfPresent(SalesReportDO::getProviderCountry, reqVO.getProviderCountry())
                .eqIfPresent(SalesReportDO::getSku, reqVO.getSku())
                .eqIfPresent(SalesReportDO::getDeveloper, reqVO.getDeveloper())
                .eqIfPresent(SalesReportDO::getTitle, reqVO.getTitle())
                .eqIfPresent(SalesReportDO::getVersion, reqVO.getVersion())
                .eqIfPresent(SalesReportDO::getProductTypeIdentifier, reqVO.getProductTypeIdentifier())
                .eqIfPresent(SalesReportDO::getUnits, reqVO.getUnits())
                .eqIfPresent(SalesReportDO::getDeveloperProceeds, reqVO.getDeveloperProceeds())
                .betweenIfPresent(SalesReportDO::getBeginDate, reqVO.getBeginDate())
                .betweenIfPresent(SalesReportDO::getEndDate, reqVO.getEndDate())
                .eqIfPresent(SalesReportDO::getCustomerCurrency, reqVO.getCustomerCurrency())
                .eqIfPresent(SalesReportDO::getCountryCode, reqVO.getCountryCode())
                .eqIfPresent(SalesReportDO::getCurrencyOfProceeds, reqVO.getCurrencyOfProceeds())
                .eqIfPresent(SalesReportDO::getAppleIdentifier, reqVO.getAppleIdentifier())
                .eqIfPresent(SalesReportDO::getCustomerPrice, reqVO.getCustomerPrice())
                .eqIfPresent(SalesReportDO::getPromoCode, reqVO.getPromoCode())
                .eqIfPresent(SalesReportDO::getParentIdentifier, reqVO.getParentIdentifier())
                .eqIfPresent(SalesReportDO::getSubscription, reqVO.getSubscription())
                .eqIfPresent(SalesReportDO::getPeriod, reqVO.getPeriod())
                .eqIfPresent(SalesReportDO::getCategory, reqVO.getCategory())
                .eqIfPresent(SalesReportDO::getCmb, reqVO.getCmb())
                .eqIfPresent(SalesReportDO::getDevice, reqVO.getDevice())
                .eqIfPresent(SalesReportDO::getSupportedPlatforms, reqVO.getSupportedPlatforms())
                .eqIfPresent(SalesReportDO::getProceedsReason, reqVO.getProceedsReason())
                .eqIfPresent(SalesReportDO::getPreservedPricing, reqVO.getPreservedPricing())
                .eqIfPresent(SalesReportDO::getClient, reqVO.getClient())
                .eqIfPresent(SalesReportDO::getOrderType, reqVO.getOrderType())
                .betweenIfPresent(SalesReportDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SalesReportDO::getBeginDate);

        // 根据 dataType 动态构建查询条件
        if (reqVO.getDataType() != null) {
            if (reqVO.getDataType() == 1) {
                queryWrapper.eq(SalesReportDO::getSubscription, "");
            } else if (reqVO.getDataType() == 2) {
                queryWrapper.ne(SalesReportDO::getSubscription, "");
            }
        }

        return selectPage(reqVO, queryWrapper);
    }

}